/**
 * @file Config.cpp
 * @author Derek Liu (yjkhtddx@sina.com)
 * @brief 
 * @version 0.1
 * @date 2020-09-10
 * 
 * @copyright Copyright Sci-Tech Laboratories (c) 2020
 * 
 */

#include <iostream>
#include "Config.h"

#include "STL_YAML/STL_YAML.h"
using namespace STL;

namespace GBXUEAN
{
    Config::Config()
    {
    }
    Config *Config::instance()
    {
        static Config instance;
        return &instance;
    }
    bool Config::Load(const std::string &path)
    {
        m_node = YAML::LoadFile(path);
        return true;
    }
    void Config::showConfig()
    {
        std::cout << "##################################" << std::endl;
        std::cout << "#####        Config        #####" << std::endl;
        std::cout << "##################################" << std::endl;
        STL_YAML::showNode(m_node);
        std::cout << "##################################" << std::endl;
    }
    std::string Config::getConfigAsString(std::string path)
    {
        std::string ret;
        if (!STL_YAML::getValue(m_node, ret, path))
        {
            std::cout << "Config get Error:" << path << std::endl;
        }
        return ret;
    }
    uint32_t Config::getConfigAsUint32(std::string path)
    {
        uint32_t ret = 0;
        if (!STL_YAML::getValue(m_node, ret, path))
        {
            std::cout << "Config get Error:" << path << std::endl;
        }
        return ret;
    }
    int32_t Config::getConfigAsInt32(std::string path)
    {
        int32_t ret = 0;
        if (!STL_YAML::getValue(m_node, ret, path))
        {
            std::cout << "Config get Error:" << path << std::endl;
        }
        return ret;
    }
    size_t Config::getConfigArraySize(std::string path)
    {
        YAML::NodeType::value type = STL_YAML::getType(m_node, path);
        if(type == YAML::NodeType::value::Sequence)
        {
            return STL_YAML::getSequenceSize(m_node, path);
        }
        return 0;
    }
} // namespace GBXUEAN